﻿@model FollowPeers.Models.Course

@{
    ViewBag.Title = "CourseAddVideo";
    FollowPeers.Models.FollowPeersDBEntities followPeersDB = new FollowPeers.Models.FollowPeersDBEntities();
    string name = Membership.GetUser().UserName;
    FollowPeers.Models.UserProfile myprofile = followPeersDB.UserProfiles.SingleOrDefault(p => p.UserName == name);
}

@Html.Partial("_Header")

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
        <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
        <script src=@Url.Content("~/Scripts/jquery.bgiframe.js") type="text/javascript"></script>
        <script src=@Url.Content("~/Scripts/jquery.mcdropdown.js") type="text/javascript"></script>
        <link rel="stylesheet" type="text/css" href="../../Content/css/jquery.mcdropdown.css" />

@Html.Partial("_SideBar2")
<div class="grid_9">
    <div class="box">
        <h2>Add Course Videos</h2>
        @using (Html.BeginForm("CourseAddVideo","Course",FormMethod.Post,new {@encType = "multipart/form-data"})) {
            @Html.ValidationSummary(true)
            <fieldset>
                <legend><a href="/Course/Details/@Model.CourseId">@Model.CourseName</a></legend>
                 <input type='file' name='video' id='video'/>
                <input type="hidden" name="CourseId" value="@Model.CourseId" />
                     
                    <p>
                        <input type="submit" name="submit" value="Save" class="btn btn-primary">
                    </p>
                    <p>
                       <table id="myDataTable" class="table table-hover" style="float: right; padding: 3px 8px; cursor: pointer;">

                                @{
                                    string path = HttpRuntime.AppDomainAppPath;
                                    string newpath = path + "\\Content\\Files\\"+Model.Owner.UserName+"\\Courses\\"+Model.CourseName+"\\";
                                    var directoryInfo = new DirectoryInfo(newpath);
                                    if (directoryInfo.Exists)
                                    {
                                        <thead>
                                            <tr>
                                                <th>
                                                    Course Videos
                                                </th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        @{
                                            string[] readtext = File.ReadAllLines(newpath + "uploadedList.txt");
                                            if (readtext == null || readtext.Length == 0)
                                            {
                                
                                                <p>There are no uploaded files</p>
                                    
                                            }

                                            else
                                            {
                                                foreach (var fileName in readtext)
                                                {
                                                        <tr>
                                                            <td>
                                                                <p><a href="#">@fileName</a></p>
                                                            </td>
                                                            <td>
                                                                    @Html.ActionLink("Download", "Download", new { downloadPath = newpath + Membership.GetUser().UserName + "\\" + fileName }) 
          
                                                            </td>
                                                            <td>
                                                                    @Html.ActionLink("Delete", "Delete_File", new { delPath = newpath + Membership.GetUser().UserName + "\\" + fileName }) 
          
                                                            </td>                           
                                                        </tr>
                                                }
                                            }
                                        }
                                        </tbody>
                                     }       
                                }
                        </table>
                    </p>
                </fieldset>
        }

        <div>
            @Html.ActionLink("Back to my Courses", "Mine","Course")
        </div>
    </div>
</div>

@Html.Partial("_Footer")
